<?php

class PagesController extends CascadeAppController
{
	var $name = "Pages";
	
	function index() {
		$pages = null;

		if (isset($this->params['url']['ext']) && $this->params['url']['ext'] == 'xml') {
			$pages = $this->Page->findAll(null, array('name', 'path'));
			
			foreach ($pages as $key => &$page) {
				$url = preg_replace('/^'.env('http_host').'(\/|$)/', '/', $page['Page']['path'], 1, $count);
				
				// give the home page a name
				if ($url == "/")
					$url = "/index";
				
				// add the extension to map to REST
				$url .= '.xml';
				
				// add the protocol onto it if the page isn't for this website (could be for another site in multi-site installs)
				if (!$count)
					$url = 'http://'.$url;
				
				$page['Page'] = array('name' => $page['Page']['name'], 'href' => $url);
			}
			
			$this->data = $pages;
			return;
		}
		
		
		//$this->data = $pages->findAll();
	}
	
	
	function view() {
		$path = func_get_args();
		$path = join("/", $path);
		
		if (isset($this->params['url']['ext']) && $this->params['url']['ext'] == 'xml') {
			$this->data = $this->Page->findByPath($path);
			return;
		}
		
		$this->autoRender = false;
		echo $path;
	}
}
?>